import React from 'react';
import item from "../../../assets/css/goods/details/item.module.css";
import {localParam} from "../../../components/common/function";

export default class ReviewComponent extends React.Component{
    constructor(){
        super();
        this.state={
            goodList:[],
            show:true
        }
    }
    componentWillMount() {
        this.getData()
    }
    getData(){
        let gid =decodeURIComponent(localParam(this.props.location.search).search.gid)
        fetch('http://vueshop.glbuys.com/api/home/reviews/index?gid='+gid+'&token=1ec949a15fb709370f&page=1')
            .then((res)=>{
                return res.json()
            }).then(res=>{
            console.log(res.data);
            if (res.code === 200) {
                this.setState({goodList:res.data});
                this.setState({show:true})
            }else {
                this.setState({show:false})
            }
        });
    }

    render() {
        return(
            <div>
                <div style={{marginTop:'80px'}} className={item.boxDivOne}>
                    <h3>商品评价 ({this.state.goodList.length})</h3>
                    {this.state.goodList.map((item,index)=>{
                        return(
                            <div key={index} className={!this.state.show?item.show:item.hide}>
                                <img src={item.head} alt=''/>
                                <span>{item.nickname}</span>
                                <p>{item.content}</p>
                                <p>{item.times}</p>
                            </div>
                        )
                    })}
                    <div className={!this.state.show?item.show:item.hide}>
                        <p className={item.boxView}>暂无评价！</p>
                    </div>
                </div>
            </div>
        )
    }
}